﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HAVTKPack
{
    /// <summary>
    /// 判断HydrolicGrid网格是否发生了改变
    /// </summary>
    public  class IsHydrolicGridChanged
    {
        /// <summary>
        /// 判断HydrolicGrid网格是否发生了改变
        /// </summary>
        /// <param name="originGrid"></param>
        /// <param name="newGrid"></param>
        /// <returns></returns>
        public static bool IsHyGridChanged(HydrolicGrid originGrid,HydrolicGrid  newGrid)
        {

            if ((originGrid ==null & newGrid !=null )||(originGrid !=null & newGrid ==null ))
            {
                return true;
            }
            if (originGrid ==null & newGrid ==null )
            {
                return false;
            }
            if (originGrid .NRows !=newGrid .NRows ||originGrid .NCols !=newGrid .NCols ||originGrid .NLayers !=newGrid .NLayers )
            {
                return true;
            }
            for (int layer = 0; layer < originGrid.NLayers; layer++)
            {
                for (int rows = 0; rows < originGrid.NRows; rows++)
                {
                    for (int cols = 0; cols < originGrid.NCols; cols++)
                    {
                        if (originGrid.Coords [rows ,cols ,layer]!=newGrid.Coords [rows ,cols ,layer ])
                        {
                            return true;
                        }

                    }
                }
            }

            return false ;
        
        }


        /// <summary>
        /// 判断HydrolicLayer是否发生了改变
        /// </summary>
        /// <param name="originLayer"></param>
        /// <param name="newLayer"></param>
        /// <returns></returns>
        public static bool IsHyLayerChanged(HydrolicLayer originLayer, HydrolicLayer newLayer)
        {

            if ((originLayer == null & newLayer != null) || (originLayer != null & newLayer == null))
            {
                return true;
            }
            if (originLayer == null & newLayer == null)
            {
                return false;
            }
            if (originLayer.NRows != newLayer.NRows || originLayer.NCols != newLayer.NCols )
            {
                return true;
            }

            //for (int layer = 0; layer < originLayer.NLayers; layer++)
            {
                for (int rows = 0; rows < originLayer.NRows; rows++)
                {
                    for (int cols = 0; cols < originLayer.NCols; cols++)
                    {
                        if (originLayer.Coords[rows, cols] != newLayer.Coords[rows, cols])
                        {
                            return true;
                        }

                    }
                }
            }

            return false;
        
        }


    }

}
